﻿using System;
using System.Web.Mvc;

namespace EasyMvc.Web.Common
{
    /// <summary>
    ///  文件服务器分离，需要得到文件服务器上文件的地址
    /// </summary>
    public static class StaticFileHelper
    {
        /// <summary>
        /// 得到图片文件，以及缩略图
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="path"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static string ImageFile(this UrlHelper helper, string path, string size = null)
        {
            if (string.IsNullOrEmpty(path))
                return helper.Content(@"~/Static/images/no_picture.jpg"); 
            
            if (size == null)
                return helper.Content(path);
            
            var ext = path.Substring(path.LastIndexOf('.'));
            var head = path.Substring(0, path.LastIndexOf('.'));
            var url = string.Format("{0}{1}_{2}{3}", string.Empty, head, size, ext);
            return url;
        }
    }
}